import { sign, verify } from 'jsonwebtoken';

export function createToken(userId: number, secret: string) {
  const token = sign(
    {
      userId,
    },
    secret,
    { expiresIn: '5s' }
  );

  return token;
}

export function getIdFromToken(token: string, secret: string) {
  const result = verify(token, secret);
  return result['userId'];
}
